package StringConstantPool;

public class demo2 {
    public static void main(String[] args) {
        String s = new String(new StringBuilder().append("aaa").append("bbb"));
        System.out.println(s == s.intern());

//        test1();
        test2();
    }

    public static void test1() {
        String s1 = "hello";
        String s2 = new String("hello");
        System.out.println(s2.intern() == s1);
    }

    private static void test2() {
        String s1 = new StringBuilder().append("aaa").append("bbb").toString();
        System.out.println(s1 == s1.intern());//true

//        StringBuilder sb=new StringBuilder();
//        sb.append("aaa");
//        sb.append("bbb");
//        String s1=sb.toString(); //new String("aaa"+new StringBuilder("bbb").toString)
//        System.out.println(s1==s1.intern());


        String s2 = new StringBuilder().append("abcdasfasc").toString();
        System.out.println(s2 == s2.intern());//false


        String s3 = new StringBuilder().append("ja").append("va").toString();
        System.out.println(s3.intern() == s3);//false
    }
}
